/**
 * Created by gengrong on 16/4/14.
 */
import { Button, Form, Input, Upload, Icon, Row, Col } from 'antd';
import { SmartForm } from 'comps/common';
import * as React from 'react';

const formLayout = {
  labelCol: { span: 4 },
  wrapperCol: { span: 18 }
};

class DevTeamForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  onSubmit(evt) {
    evt.preventDefault();
    this.props.smartSubmit((values) => {
      return this.props.onSaveDevTeam(values);
    });
  }

  render() {
    const { getFieldProps, setFieldsValue } = this.props.form;
    const nameProps = getFieldProps('name', {
      rules: [
        { required: true, message: '请填写开发组名称' }
      ]
    });
    const logoProps = getFieldProps('logo', {});
    const uploadProps = {
      action: '/api/images/upload',
      listType: 'picture-card',
      onChange: (info) => {
        if (!info.file.response) {
          return;
        }
        this.setState({ logoFileList: info.fileList.slice(-1) });
        setFieldsValue({ logo: info.file.response.url });
      }
    };

    return (
      <Form horizontal form={this.props.form} onSubmit={::this.onSubmit}>
        <Form.Item required label='名称：' {...formLayout}>
          <Input {...nameProps} placeholder='输入开发组名称'/>
        </Form.Item>
        <Form.Item label='Logo：' {...formLayout}>
          <Input type='hidden' {...logoProps}/>
          <Upload {...uploadProps} fileList={this.state.logoFileList}>
            <Icon type='plus'/>
            <div className='ant-upload-text'>上传图片</div>
          </Upload>
        </Form.Item>
        <Form.Item label='描述：' {...formLayout}>
          <Input type='textarea' {...getFieldProps('desc')} placeholder='输入开发组描述'/>
        </Form.Item>
        <Row>
          <Col span='18' offset='4'>
            <Button loading={this.props.submiting} type='primary' htmlType='submit'>提交</Button>
          </Col>
        </Row>
      </Form>
    );
  }
}
DevTeamForm = Form.create()(SmartForm.beSmart()(DevTeamForm));

export default DevTeamForm;
